@extends('layouts.app')
@section('title','写信')
@section('css')
    <link href="http://cdn.bootcss.com/iCheck/1.0.2/skins/all.css" rel="stylesheet">
@endsection
@section('content')
    @include('vendor.ueditor.assets')
    <div class="container">
        <div class="row">
            <div class="col-md-10 col-md-offset-1 ">
                <div class="panel panel-collapse">
                    <div class="panel-heading">
                        <div class="panel-title panel" >写信</div>
                    </div>
                    <div class="panel-body">
                        <form method="post" action="{{url('letters')}}" id="create_form">

                            <div class="form-group{{ $errors->has('to') ? ' has-error' : '' }} ">
                                <label for="title">收件人</label>
                                <input type="text" id="title" name="to" value="{{old('to')}}"  class="form-control" placeholder="任意一个邮箱地址">

                                @if ($errors->has('to'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('to') }}</strong>
                                    </span>
                                @endif
                            </div>

                            <div class="form-group{{ $errors->has('send_time') ? ' has-error' : '' }} ">
                                <label for="date-picker">寄送时间</label>
                                <input type="datetime-local" name="send_time"  value="{{old('send_time')}}" class="form-control">

                                @if ($errors->has('send_time'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('send_time') }}</strong>
                                    </span>
                                @endif

                            </div>
                            <div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
                                <label for="title">标题</label>
                                <input type="text" id="title" value="{{old('title')}}" name="title" class="form-control" placeholder="邮件标题">

                                @if ($errors->has('title'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('title') }}</strong>
                                    </span>
                                @endif
                            </div>

                            <div class="form-group{{ $errors->has('content') ? ' has-error' : '' }}">
                                <!-- 编辑器容器 -->
                                <label for="container">内容</label>
                                <script id="container" name="content" style="height: 300px"  class="editor" type="text/plain">{!! old('content') !!}</script>
                                @if ($errors->has('content'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('content') }}</strong>
                                    </span>
                                @endif
                            </div>

                            <div class="form-group{{ $errors->has('content') ? ' has-error' : '' }}">
                                <label for="yes" id="tip_yes">公开</label>&nbsp;&nbsp;&nbsp;
                                <input id="yes" {{old('scope')==1?"checked":""}} onclick=" layer.tips('你的信将出现在“读信”里面，所有人都可以看到，投递后亦可修改为仅自己可见', '#tip_yes',{tips: [1, '#3595CC'],time: 4000});" value="1" type="radio" name="scope" >
                                <label for="no" id="tip_no">不公开</label>&nbsp;&nbsp;&nbsp;
                                <input {{old('scope')==2?"checked":""}} onclick="layer.tips('仅自己可见，投递后亦可修改为所有人可见', '#tip_no',{tips: [1, '#3595CC'],time: 4000});" id="no" value="2" type="radio" name="scope" >
                                @if ($errors->has('scope'))
                                    <span class="help-block">
                                        <strong style="color:#a94442;">{{ $errors->first('scope') }}</strong>
                                    </span>
                                @endif
                            </div>
                            <input type="hidden" id="status" name="status" value="1">
                            {{csrf_field()}}
                            <input type="button" class="btn btn-success btn-block"  onclick="send();" value="写信">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="{{ asset('js/jq.js') }}"></script>
    <script src="{{ asset('layer/layer.js') }}"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">

        var ue = UE.getEditor('container', {
            toolbars: [
                ['bold', 'italic', 'underline', 'strikethrough', 'blockquote', 'insertunorderedlist', 'insertorderedlist', 'justifyleft','justifycenter', 'justifyright',  'link', 'insertimage', 'fullscreen']
            ],
            elementPathEnabled: false,
            enableContextMenu: false,
            autoClearEmptyNode:true,
            wordCount:false,
            imagePopup:false,
            autotypeset:{ indent: true,imageBlockLine: 'center' }
        });
        function send() {
            layer.confirm('不犹豫，不后悔。提交后，不提供删除功能，我希望你能够为自己的行为负责，而不是寄希望于删掉以前的信。', {
                btn: ['嗯，我同意','算了，我还没想好'] //按钮
            }, function(){
                $("#create_form").submit();
                layer.msg('加载中', {icon: 16,shade: 0.1});
            }, function(){
                layer.confirm('那保存到草稿箱？下次想好再投递', {
                    btn: ['嗯，好的', '等会儿再说']
                },function () {
                    $("#status").val(2);
                    $("#create_form").submit();
                    layer.msg('加载中', {icon: 16,shade: 0.1});
                });
            });
        }


    </script>


@endsection
